home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-13 / emacs16d.zip / C.MIN < prev    next >
Text File  |  1991-09-04  |  7KB  |  350 lines

  1.  
  2.  
  3. Name:Cfilename
  4.        Original: the MINT EMACS C mode by Johnathan Vail
  5.        GNU Emacs like C mode by Hiroshi Onishi
  6.  
  7.  
  8.     The code here is to be given freely to all Freemacs users. This C
  9. mode provides the following features:
  10.  
  11.     o  Automatic left-curly-matching and proper indenting for the
  12.         right brace.
  13.  
  14.     o  "Intelligent" auto-indenting (follow indenting level of current
  15.         open left brace plus one of few parameters).
  16.  
  17.     o  Selectable {tab,indent,...} size with the variable c-*.
  18.  
  19.     o  A new level command for opening new levels of code.
  20.  
  21. KEYS in C mode:
  22.  
  23.     Return -- Return will open a new line and if auto-indent is on it
  24.         will indent the proper amount for the current level.
  25.         If breaking a line it will indent a little more.
  26.  
  27.       Tab  -- If at the end of a line Tab inserts a <TAB> (^I).
  28.         Otherwise the line is re-indented to the proper amount.
  29.  
  30.        }   -- If on a line of code this simply shows the matching
  31.         open {.  Otherwise it will indent itself to the proper
  32.         depth and show the matching open {.
  33.  
  34.       M-{  -- This open a new level by inserting both a { and a } and
  35.         opening a line in between, indented to the proper amount.
  36.  
  37. OPERATION:
  38.  
  39.     When a .c or .h file is visited C mode is invoked.  Otherwise it
  40. can be entered by M-X C-mode.  A new function, Fun-mode will set
  41. Fun)damental as the major mode (I changed my Fundamental to Fun).  My
  42. default is to use a <TAB> to denote a new level.  If you do not like this
  43. then you can change the variable #(Ctabs) to be whatever whitespace you
  44. like.  Notice also that if you override the indenting that the subsequent
  45. indenting will follow.  Also notice that it doesn't matter where on the
  46. line the { is.  Anyway, SHARE and ENJOY.
  47.  
  48.             Johnathan Vail, N1DXG
  49.             Data General, Durham NH (603) 862-6562
  50.             vail_j@dur08.ceo.dg.com
  51. [*]c[*]
  52.  
  53.  
  54. Name:C-argdecl-indent
  55. [*]0[*]
  56.  
  57.  
  58. Name:C-brace-imaginary-offset
  59. [*]0[*]
  60.  
  61.  
  62. Name:C-brace-offset
  63. [*]8[*]
  64.  
  65.  
  66. Name:C-continued-statement-offset
  67. [*]-4[*]
  68.  
  69.  
  70. Name:C-indent-level
  71. [*]8[*]
  72.  
  73.  
  74. Name:C-label-offset
  75. [*]-8[*]
  76.  
  77.  
  78. Name:C:C-newlevel
  79. This will open a new level of C code braces.
  80. [*]
  81. #(is,({
  82. ))#(is,#(Cnext-indent))
  83. ##(is,(
  84. )#(Ccurrent-indent)})
  85. #(sp,^<)
  86. [*]
  87.  
  88.  
  89. Name:C:Ccolon
  90. [*]#(is,:)#(Cindent)[*]
  91.  
  92.  
  93. Name:C:Clbrace
  94. If we are putting our { on a line of code the just flash it.
  95. [*]#(pm,2)
  96. #(lp,[ ##(bc,9,d,a)]*,,x)
  97. #(l?,^,.,0,1)
  98. #(==,##(rm,1),,(
  99.     #(dm,^)
  100.     #(==,#(Ccurrent-indent)#(cnode),top,,
  101.     (#(is,#(Cnext-indent,#(++,#(C-brace-offset),#(C-indent-level)))))
  102.     )
  103. ))
  104. #(pm)
  105. #(is,{)
  106. [*]
  107.  
  108.  
  109. Name:C:Cnewline-and-indent
  110. C mode newline with auto indent, current indent level, and if breaking a line
  111. then indent it a little more.
  112. [*]#(Fcrlf)
  113. #(is,#(Cnext-indent))
  114. #(==,#(rc,$),0,,(#(is,#(Ctabs))))[*]
  115.  
  116.  
  117. Name:C:Crbrace
  118. If we are putting our } on a line of code the just flash it, otherwise match
  119. the indenting of the open { and then flash it.
  120. [*]#(pm,2)
  121. #(lp,[ ##(bc,9,d,a)]*,,x)
  122. #(l?,^,.,0,1)
  123. #(==,##(rm,1),,(
  124.     #(dm,^)
  125.     #(==,#(Cindent-imaginary),n,(#(is,#(Ccurrent-indent))),
  126.         (#(is,#(Cnext-indent,#(C-brace-imaginary-offset)))))
  127. ))
  128. #(pm)
  129. #(Fflash-paren,{,})
  130. [*]
  131.  
  132.  
  133. Name:C:Ctab
  134. This will indent the C line to the appropriate amount or insert #(Ctabs) if EOL
  135. [*]
  136. #(==,#(rc,$),0,(
  137.     #(==,#(rc,^),0,(#(Cindent)),(#(is,#(Ctabs))))
  138. ),(#(Cindent)
  139. ))
  140. [*]
  141.  
  142.  
  143. Name:Ccurrent-indent
  144. Return the indenting of the previous open {.
  145. [*]#(pm,4)
  146. #(sm,3,[)
  147. #(==,#(Fflash-paren-do,1,{,}),yes,(
  148.     #(Cget-indent)#(ds,cnode)
  149. ),#(ds,cnode,top))
  150. #(sp,0)
  151. #(pm)
  152. [*]
  153.  
  154.  
  155. Name:Cget-indent
  156. Return the indenting of the current line.
  157. [*]#(pm,3)
  158. #(lp,[ ##(bc,9,d,a)]*,,R)
  159. #(l?,^,$,0,1)
  160. #(sp,0)
  161. ##(rm,1)
  162. #(sp,2)
  163. #(pm)[*]
  164.  
  165.  
  166. Name:Cindent
  167. [*]
  168. #(pm,3)
  169. #(lp,^[ ##(bc,9,d,a)]*,,R)
  170. #(l?,^,$,,1)
  171. #(sp,1)
  172. #(dm,^)
  173. #(Fcase,#(rm,>),
  174.     (},(
  175.         #(==,#(Cindent-imaginary),n,(
  176.                 #(is,#(Ccurrent-indent))
  177.             ),(#(is,#(Cnext-indent,
  178.                 #(C-brace-imaginary-offset)))
  179.             )
  180.         )
  181.     )),
  182.     ({,(
  183.         #(==,#(Ccurrent-indent)#(cnode),top,,
  184.         (#(is,#(Cnext-indent,
  185.             #(++,#(C-brace-offset),#(C-indent-level)))))
  186.         )
  187.     )),
  188.     (
  189.         #(is,#(Cnext-indent,#(++,#(C-indent-level),#(++,
  190.             #(**,#(Cindent-more),#(C-continued-statement-offset)),
  191.             #(++,#(Clabel-indent),#(==,#(Cindent-imaginary),y,(#(C-brace-imaginary-offset))))
  192.         ))))
  193.     )
  194. )
  195. #(sp,2)
  196. #(pm)
  197. [*]
  198.  
  199.  
  200. Name:Cindent-continued
  201. [*]
  202. #(lp,[;{}],,R)
  203. #(==,#(l?,.,[,,2,y),y,(
  204.     #(sp,2)#(SELF-do,if)
  205.     #(sp,2)#(SELF-do,else,x)
  206.     #(sp,2)#(SELF-do,do,x)
  207.     #(sp,2)#(SELF-do,while)
  208.     #(sp,2)#(SELF-do,switch)
  209.     #(sp,2)#(lp,for[ ##(bc,9,h,a)]*##(bc,28,h,a)[^;]*;[^;]*;,,R)
  210.     #(==,#(l?,.,[,3,4,y),y,(
  211.         #(==,#(rc,4),0,( #(sm,1,3)#(sp,3)#(ds,temp,#(++,#(temp),1))#(SELF) ))
  212.     ))
  213. ))
  214. [*]
  215.  
  216.  
  217. Name:Cindent-continued-do
  218. [*]
  219. #(==,arg2,,(
  220. #(==,#(lp,[\n ##(bc,9,d,a)]arg1[ ##(bc,9,h,a)]*##(bc,28,h,a),,R)#(l?,.,1,,3,y)
  221.     ,y,(#(sp,3)#(ds,temp,#(++,#(temp),1))#(SELF,arg1)))
  222. ),(
  223. #(==,#(lp,[\n ##(bc,9,d,a)]arg1,,R)#(l?,.,1,,3,y)
  224.     ,y,(#(sp,3)#(ds,temp,#(++,#(temp),1))#(SELF,arg1)))
  225. ))
  226. [*]
  227.  
  228.  
  229. Name:Cindent-imaginary
  230. [*]
  231. #(pm,4)
  232. #(sm,3,[)
  233. #(==,#(Fflash-paren-do,1,{,}),yes,(
  234.     #(lp,[ ##(bc,9,d,a)]*,,x)
  235.     #(l?,^,.,1,2)
  236.     #(sp,2)
  237.     #(==,#(rm,>),{,(n),(y))
  238. ))
  239. #(sp,0)
  240. #(pm)
  241. [*]
  242.  
  243.  
  244. Name:Cindent-more
  245. [*]
  246. #(pm,5)
  247. #(==,arg1,,(#(sm,1,^)))
  248. #(ds,temp,0)
  249. #(Cindent-continued)
  250. #(sp,0)
  251. #(pm)
  252. #(gs,temp)
  253. [*]
  254.  
  255.  
  256. Name:Clabel-indent
  257. [*]
  258. #(lp,^[\n #(bc,9,d,a)]*[a-zA-Z0-9_]*:\|^[\n #(bc,9,d,a)]*case[^?]*:,,r)
  259. #(==,#(l?,^,$,,,y),y,(#(C-label-offset)))
  260. [*]
  261.  
  262.  
  263. Name:Cnext-indent
  264. Make next indent
  265. [*]
  266. #(ds,temp,#(Ccurrent-indent)#(Ctabs,(arg1))( ))
  267. #(==,#(cnode),top,
  268.     (#(Ctabs,#(C-argdecl-indent))
  269.     ),(
  270.     ##(fm,temp,( ))#(Cspace2tab,##(temp))
  271.     )
  272. )
  273. [*]
  274.  
  275.  
  276. Name:Cspace2tab
  277. [*]
  278. #(ds,tmp,#(//,#(nc,arg1),8))
  279. #(Floop,(##(bc,9,h,a)),#(tmp))
  280. #(Floop,( ),#(--,#(nc,arg1),#(**,##(tmp),8)))
  281. [*]
  282.  
  283.  
  284. Name:Cstaydown-do.47
  285. [*]#(pm,2)
  286. #(==,##(rm,<),*,(
  287.     #(sp,>)
  288.     #(==,#(Fbackward-find-paren,[,/*,*/),yes,(
  289.         #(sm,1)
  290.         #(sp,0>)
  291.         #(Fstaydown-mark,1)
  292.     ))
  293. ),(
  294.     #(sp,>)
  295.     #(==,##(rm,>),*,(
  296.         #(sp,<)
  297.         #(==,#(Fforward-find-paren,],/*,*/),yes,(
  298.             #(sm,1)
  299.             #(sp,0)
  300.             #(Fstaydown-mark,1)
  301.         ))
  302.     ),(
  303.         #(sp,<)
  304.         #(sm,1,>)
  305.         #(Fstaydown-mark,1)
  306.     ))
  307. ))
  308. #(pm)[*]
  309.  
  310.  
  311. Name:Ctabs
  312. A function that returns the indentation string.
  313. [*]#(Floop,( ),#(==,arg1,,#(C-indent-level),(arg1)))[*]
  314.  
  315.  
  316. Name:F:C-mode
  317. [*]
  318. #(Fexit-mode)
  319. #(n?,Cfilename,,(
  320.     #(Fload-lib,C)
  321. ))
  322. #(Flocal-bind-key,K.C-j,C:Cnewline-and-indent)
  323. #(Flocal-bind-key,K.},C:Crbrace)
  324. #(Flocal-bind-key,K.{,C:Clbrace)
  325. #(Flocal-bind-key,K.:,C:Ccolon)
  326. #(Flocal-bind-key,K.M-{,C:C-newlevel)
  327. #(Flocal-bind-key,K.Tab,C:Ctab)
  328. #(Flocal-bind-key,K.C-i,C:Ctab)
  329. #(Flocal-bind-key,open-paren-hook,(
  330.     ##(sp,{)
  331. ))
  332. #(Flocal-bind-key,staydown-hook,(
  333.     #(n?,Cstaydown-do.ARG1,(
  334.         #(Cstaydown-do.ARG1)
  335.     ),(
  336.         #(Pstaydown-do-do,ARG1)
  337.     ))
  338. ))
  339. #(mp,staydown-hook,,ARG1)
  340. #(Fset-modename,C)
  341. #(ds,syntax,##(Fsyntax))
  342. #(Fmodify-syntax,syntax,##(bc,#),1)
  343. #(st,syntax)
  344. [*]
  345.  
  346.  
  347. Name:F:c-mode
  348. [*]#(F:C-mode)[*]
  349.  
  350.